/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cqcis.uip.base.framework.core.impl;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import com.cqcis.uip.base.framework.core.ContextStartNotify;

/**
 * 应用已经启动监听器
 * 
 * @author huangmy
 * @date   2009-3-26
 */
public class ApplicationStartedListener implements ApplicationListener {

	public void onApplicationEvent(ApplicationEvent event) {
		if (event instanceof ContextRefreshedEvent) {
			// 已经启动完成
			ContextRefreshedEvent contextEvent = (ContextRefreshedEvent)event;
			
			ApplicationContext applicationContext = contextEvent.getApplicationContext();
			String[] beanNames = applicationContext.getBeanNamesForType(ContextStartNotify.class);
			if (beanNames != null) {
				for (String beanName : beanNames) {
					ContextStartNotify notifyer = (ContextStartNotify)applicationContext.getBean(beanName);
					if (notifyer != null) {
						notifyer.notifyContextStart();
					}
				}
			}
		}
	}
}
